﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Extjs_ReGSharp.Sorting
{
	internal class Sorter<T>
	{
		#region Data Memebers

		public ISortingBehaviour<T> SortingBehaviour { get; private set; }
		private SortingOrderController m_OrderController;

		#endregion

		#region Public Methods

		public bool HasSortingBehaviour
		{
			get
			{
				return SortingBehaviour != null;
			}
		}

		#endregion

		#region Constructor

		public Sorter(ISortingBehaviour<T> behaviour, SortingOrderController orderController)
		{
			SortingBehaviour = behaviour;
			m_OrderController = orderController;
		}

		#endregion

		#region Public Methods

		public int Compare(T firstInstance, T secondInstance)
		{
			int behaviourCompareResult = SortingBehaviour.Compare(firstInstance, secondInstance);

			int orderedResult = m_OrderController.ModifyResultByOrder(behaviourCompareResult);

			return orderedResult;
		}

		#endregion
	}
}
